#include "server.h"
#include "serial.h"
#include "mqtt.h"

int main(int argc, char *argv[])
{
    if(argc < 2)
    {
        printf("usage:%s <port>\n", argv[0]);
        return -1;
    }
    //初始化服务器
    if(init_network(atoi(argv[1])) < 0)
    {
        puts("init_server err");
        return -1;
    }
#ifdef DEV_SIMULATION
    if (0 != mqtt_init())
    {
        puts("init_mqtt err");
        return -1;
    }

    if(mqtt_subscribe(SUB_TOPIC) < 0)
    {
        printf("sub err");
        return -1;
    }

#else
    if (0 != serial_init())
    {
        puts("init_mqtt err");
        return -1;
    }
#endif

    while (1)
    {
        sleep(10);
    }

    close_network();

    return 0;
}
